import Vue from "vue";
import Router from "vue-router";
import Index from "@/view/Index";
import { getStore } from "../utils/local.js";
import { resolve } from "path";

Vue.use(Router);

const router = new Router({
  base: "/home/",
  routes: [
    {
      path: "/",
      name: "index",
      component: Index
    },
    {
      path: "/home",
      name: "home",
      component: resolve => require(["../view/Home.vue"], resolve),
      children: [
        {
          path: "/frontUser",
          name: "前端用户管理",
          component: resolve => require(["../view/user/frontUser.vue"], resolve)
        },
        {
          path: "/users",
          name: "用户列表",
          component: resolve => require(["../view/user/Users.vue"], resolve)
        },
        {
          path: "/roles",
          name: "角色列表",
          component: resolve => require(["../view/user/Roles.vue"], resolve)
        },
        {
          path: "/privilege",
          name: "权限列表",
          component: resolve => require(["../view/user/Privilege.vue"], resolve)
        },
        {
          path: "/ad",
          name: "图片广告列表",
          component: resolve => require(["../view/file/Pic.vue"], resolve)
        },
        {
          path: "/themeAd",
          name: "专题广告管理",
          component: resolve =>
            require(["../view/file/ThemeNewAd.vue"], resolve)
        },
        {
          path: "/themeAdType",
          name: "专题广告分类",
          component: resolve => require(["../view/file/AdType.vue"], resolve)
        },
        {
          path: "/themeAdChildType",
          name: "专题广告子分类",
          component: resolve =>
            require(["../view/file/AdChildType.vue"], resolve)
        },
        {
          path: "/expert",
          name: "专家列表",
          component: resolve => require(["../view/expert/Expert.vue"], resolve)
        },
        {
          path: "/domain",
          name: "领域管理",
          component: resolve => require(["../view/expert/Domain.vue"], resolve)
        },
        {
          path: "/notification",
          name: "通知公告列表",
          component: resolve =>
            require(["../view/notice/noticeList.vue"], resolve)
        },
        {
          path: "/notifTongji",
          name: "统计",
          component: resolve =>
            require(["../view/notice/statistics.vue"], resolve)
        },
        {
          path: "/courseList",
          name: "课程列表",
          component: resolve =>
            require(["../view/project/projectList.vue"], resolve)
        },
        {
          path: "/courseCategory",
          name: "课程分类",
          component: resolve =>
            require(["../view/project/projectType.vue"], resolve)
        },
        {
          path: "/downloadList",
          name: "下载文件列表",
          component: resolve =>
            require(["../view/download/downloadList.vue"], resolve)
        },
        {
          path: "/paterner",
          name: "合作单位列表",
          component: resolve =>
            require(["../view/friendly/friendly.vue"], resolve)
        },
        {
          path: "/paternerType",
          name: "栏目类型管理",
          component: resolve => require(["../view/friendly/type.vue"], resolve)
        },
        {
          path: "/videoList",
          name: "音视频列表",
          component: resolve => require(["../view/file/Video.vue"], resolve)
        },
        {
          path: "/articlelist",
          name: "文章列表",
          component: resolve =>
            require(["../view/article/ArticleList.vue"], resolve)
        },
        {
          path: "/articleType",
          name: "要闻动态分类",
          component: resolve =>
            require(["../view/article/ArticleType.vue"], resolve)
        },
        {
          path: "/hotNews",
          name: "热点资讯列表",
          component: resolve =>
            require(["../view/hotNews/hotNews.vue"], resolve)
        },
        {
          path: "/hotNewsType",
          name: "热点资讯分类管理",
          component: resolve =>
            require(["../view/hotNews/hotNewsType.vue"], resolve)
        },
        {
          path: "/forumList",
          name: "会议论坛列表",
          component: resolve => require(["../view/forum/forum.vue"], resolve)
        },
        {
          path: "/forumType",
          name: "会议论坛分类管理",
          component: resolve =>
            require(["../view/forum/forumType.vue"], resolve)
        },
        {
          path: "/decisionList",
          name: "决策调研列表",
          component: resolve => require(["../view/decison/list.vue"], resolve)
        },
        {
          path: "/decisionType",
          name: "决策调研分类",
          component: resolve => require(["../view/decison/type.vue"], resolve)
        },
        {
          path: "/decisionComment",
          name: "决策调研评论管理",
          component: resolve =>
            require(["../view/decison/comment.vue"], resolve)
        },
        {
          path: "/decisionQA",
          name: "决策调研问卷管理",
          component: resolve =>
            require(["../view/decison/question.vue"], resolve)
        },
        {
          path: "/pointList",
          name: "学者观点列表",
          component: resolve => require(["../view/point/list.vue"], resolve)
        },
        {
          path: "/pointType",
          name: "学者观点类型",
          component: resolve => require(["../view/point/type.vue"], resolve)
        },
        {
          path: "/thinkTankList",
          name: "专业智库列表",
          component: resolve => require(["../view/thinkTank/list.vue"], resolve)
        },
        {
          path: "/thinkTankType",
          name: "专业智库类型",
          component: resolve => require(["../view/thinkTank/type.vue"], resolve)
        },
        {
          path: "/alliance",
          name: "智库联盟",
          component: resolve => require(["../view/org/alliance.vue"], resolve)
        },
        {
          path: "/activity",
          name: "联盟活动",
          component: resolve => require(["../view/org/activity.vue"], resolve)
        },
        {
          path: "/organization",
          name: "智库机构",
          component: resolve => require(["../view/org/org.vue"], resolve)
        },
        {
          path: "/orgJg",
          name: "智库单位机构",
          component: resolve => require(["../view/org/orgJg.vue"], resolve)
        },
        {
          path: "/orgLeader",
          name: "智库领导",
          component: resolve => require(["../view/org/leader.vue"], resolve)
        },
        {
          path: "/orgDynamic",
          name: "机构动态",
          component: resolve => require(["../view/org/dynamic.vue"], resolve)
        },
        {
          path: "/orgProjectType",
          name: "机构研究项目类型",
          component: resolve =>
            require(["../view/org/orgProjectType.vue"], resolve)
        },
        {
          path: "/orgProject",
          name: "机构研究项目",
          component: resolve => require(["../view/org/orgProject.vue"], resolve)
        },
        {
          path: "/orgPublishType",
          name: "机构出版物类型",
          component: resolve =>
            require(["../view/org/publishType.vue"], resolve)
        },
        {
          path: "/orgPublish",
          name: "机构出版物",
          component: resolve => require(["../view/org/publish.vue"], resolve)
        },
        {
          path: "/orgResultType",
          name: "机构研究成果类型",
          component: resolve => require(["../view/org/resultType.vue"], resolve)
        },
        {
          path: "/orgResult",
          name: "机构研究成果",
          component: resolve => require(["../view/org/result.vue"], resolve)
        },
        {
          path: "/specialType",
          name: "决策专刊类型",
          component: resolve => require(["../view/special/type.vue"], resolve)
        },
        {
          path: "/specialParentType",
          name: "决策专刊总类型",
          component: resolve =>
            require(["../view/special/parentType.vue"], resolve)
        },
        {
          path: "/special",
          name: "决策专刊列表",
          component: resolve => require(["../view/special/list.vue"], resolve)
        },
        {
          path: "/ttResultType",
          name: "智库成果管理",
          component: resolve => require(["../view/ttResult/type.vue"], resolve)
        },
        {
          path: "/ttResult",
          name: "智库成果列表",
          component: resolve => require(["../view/ttResult/list.vue"], resolve)
        },
        {
          path: "/indexpic",
          name: "首页图片管理",
          component: resolve => require(["../view/file/Pic.vue"], resolve)
        },
        {
          path: "/friend",
          name: "友情链接",
          component: resolve =>
            require(["../view/friendly/friendly.vue"], resolve)
        },
        {
          path: "/demo",
          name: "demo",
          component: resolve => require(["../view/Demo.vue"], resolve)
        },
        {
          path: "/notice",
          name: "公告列表",
          component: resolve =>
            require(["../view/notice/noticeList.vue"], resolve)
        },
        {
          path: "/questionnaire",
          name: "问卷列表",
          component: resolve =>
            require(["../view/questionnaire/list.vue"], resolve)
        },
        {
          path: "/questionnaireSubType",
          name: "题目类型",
          component: resolve =>
            require(["../view/questionnaire/type.vue"], resolve)
        },
        {
          path: "/questionnaireSubject",
          name: "问卷题目列表",
          component: resolve =>
            require(["../view/questionnaire/subjectList.vue"], resolve)
        },
        {
          path: "/addressBook",
          name: "通讯录",
          component: resolve =>
            require(["../view/addressBook/addressBook.vue"], resolve)
        },
        {
          path: "/orgEvaType",
          name: "智库评价类型",
          component: resolve => require(["../view/orgEva/type.vue"], resolve)
        },
        {
          path: "/orgEvaList",
          name: "智库评价列表",
          component: resolve => require(["../view/orgEva/list.vue"], resolve)
        },
        {
          path: "/userCenter",
          name: "个人栏目",
          component: resolve =>
            require(["../view/userCenter/usetCentet.vue"], resolve)
        },
        {
          path: "/learn",
          name: "学习资料",
          component: resolve => require(["../view/learn/learn.vue"], resolve)
        }
      ]
    }
  ]
});

router.beforeEach((to, from, next) => {
  const token = getStore("authToken");
  if (to.path == "/") {
    next();
  } else {
    if (token) {
      next();
    } else {
      next("/");
    }
  }
});

export default router;
